import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./static/iconfont/iconfont.css";
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
// 添加全局拦截守卫
router.beforeEach((to, from, next) => {
  // 验证是否有token
  let token = store.state.token;
  document.title = "羽街电商管理系统";
  if (to.path != "/login") {
    if (!token) {
      next({
        path: "/login",
      });
      return;
    }
    next();
  } else {
    next();
  }
});

createApp(App)
  .use(store)
  .use(router)
  .use(ElementPlus, {
    locale: zhCn,
  })
  .mount("#app");
